home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 131 / XENIATGM131.iso / Shareware / openOffice.org 641 / Windows / f_0047 / sbasic.jar / text / sbasic / common / 03090301.xml < prev    next >
Extensible Markup Language  |  2001-09-07  |  6KB  |  84 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>GoSub...Return Statement [Runtime]</title><meta name="filename" content="text/sbasic/common/03090301"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         table.Tabelle1{
  5.                 }
  6.         span.Tabelle1A{
  7.                 width:1.499cm;}
  8.         span.Tabelle1B{
  9.                 width:16.498cm;}
  10.         tr.Tabelle11{
  11.                 }
  12.         td.Tabelle1A1{
  13.                 }
  14.         table.Tabelle2{
  15.                 }
  16.         span.Tabelle2A{
  17.                 width:1.499cm;}
  18.         span.Tabelle2B{
  19.                 width:16.498cm;}
  20.         tr.Tabelle21{
  21.                 }
  22.         td.Tabelle2A1{
  23.                 }
  24.         p.P1{
  25.                 }
  26.         span.T1{
  27.                 font-weight:bold;}
  28.         span.fr1{
  29.                 }
  30.         </style></head><body>
  31.   
  32.   
  33.   <help:to-be-embedded Eid="gosubreturn" xmlns:help="http://openoffice.org/2000/help">
  34.   <p class="Head1"><help:link Id="66539">GoSub...Return Statement [Runtime]</help:link></p>
  35.   <p class="Paragraph">Calls a subroutine within a Sub or Function indicated by a label. The statements following the label are executed until the next Return statement; thereafter the program continues with the statement following the <span style="font-weight:bold;">GoSub </span>statement.</p>
  36.   </help:to-be-embedded>
  37.   <p class="Paragraph"><span class="T1">Syntax</span>:</p>
  38.   <p class="Paragraph">see Parameter see</p>
  39.   <p class="Paragraph"><span class="T1">Parameter</span>:</p>
  40.   <p class="Paragraph">Sub/Function</p>
  41.   <p class="Paragraph">statement block</p>
  42.   <p class="Paragraph"><help:key-word value="GoSub" tag="kw66539_1" xmlns:help="http://openoffice.org/2000/help"/>GoSub Label</p>
  43.   <p class="Paragraph">statement block</p>
  44.   <p class="Paragraph">GoSub Label</p>
  45.   <p class="Paragraph">Exit Sub/Function</p>
  46.   <p class="Paragraph">Label:</p>
  47.   <p class="Paragraph">statement block</p>
  48.   <p class="Paragraph">Return</p>
  49.   <p class="Paragraph">End Sub/Function</p>
  50.   <p class="Paragraph">The <span class="T1">GoSub</span> statement is used to call a local subroutine from within a Sub or Function, indicated by a label that marks the first line of the subroutine. To name of the label must end with a colon (":"). After reaching the <span class="T1">GoSub</span> statement, the program continues execution with the statement directly following the label. The subsequent statements and functions are executed until the next <span class="T1">Return</span> statement. The program then returns to the <span class="T1">GoSub</span> statement and continues with the statement following the <span class="T1">GoSub</span> statement.</p>
  51.   <table><tr class="Tabelle11"><th class="Tabelle1A1" style="text-align:left;"><span class="Tabelle1A">
  52.       <p class="TextInTable"><draw:image draw:style-name="fr1" draw:name="HIND_1" text:anchor-type="paragraph" svg:width="0.847cm" svg:height="0.847cm" draw:z-index="0" xlink:href="65640" xlink:type="simple" xlink:show="embed" xlink:actuate="onRequest" draw:filter-name="GIF - Graphics Interchange" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:text="http://openoffice.org/2000/text" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  53.       </p>
  54.      </span></th><th class="Tabelle1A1" style="text-align:left;"><span class="Tabelle1B">
  55.       <p class="TextInTable">If the program encounters a Return statement not preceded by <span class="T1">GoSub</span>, Star Basic returns an error message. Use <span class="T1">Exit Sub</span> or <span class="T1">Exit Function</span> to ensure that the program leaves a Sub or Function before reaching the next Return statement.</p>
  56.      </span></th></tr></table>
  57.   <p class="Paragraph"/>
  58.   <table><tr class="Tabelle21"><th class="Tabelle2A1" style="text-align:left;"><span class="Tabelle2A">
  59.       <p class="TextInTable"><draw:image draw:style-name="fr1" draw:name="HIND_2" text:anchor-type="paragraph" svg:width="0.847cm" svg:height="0.847cm" draw:z-index="1" xlink:href="66732" xlink:type="simple" xlink:show="embed" xlink:actuate="onRequest" draw:filter-name="GIF - Graphics Interchange" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:text="http://openoffice.org/2000/text" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/>
  60.       </p>
  61.      </span></th><th class="Tabelle2A1" style="text-align:left;"><span class="Tabelle2B">
  62.       <p class="TextInTable">GoSub and Return are relicts from old BASIC dialects, retained only for compatibility reasons. If you often use GoSub and Return, your program will tend to become unreadable. Subs or Functions are preferable.</p>
  63.      </span></th></tr></table>
  64.   <p class="Paragraph"/>
  65.   <p class="Paragraph">The following example demonstrates the use of <span class="T1">GoSub</span> and <span class="T1">Return </span>. By executing a program section twice, the program calculates the square root of two numbers entered by the user.</p>
  66.   <p class="Paragraph"><span class="T1">Example:</span></p>
  67.   <p class="PropText">Sub ExampleGoSub</p>
  68.   <p class="PropText">dim iInputa as Single</p>
  69.   <p class="PropText">dim iInputb as Single</p>
  70.   <p class="PropText">dim iInputc as Single</p>
  71.   <p class="PropText">iInputa = Int(InputBox$ "Enter the first number: ","NumberInput"))</p>
  72.   <p class="PropText">iInputb = Int(InputBox$ "Enter the second number: ","NumberInput"))</p>
  73.   <p class="PropText">iInputc=iInputa</p>
  74.   <p class="PropText">GoSub SquareRoot</p>
  75.   <p class="PropText">Print "The square root of";iInputa;" is";iInputc</p>
  76.   <p class="PropText">iInputc=iInputb</p>
  77.   <p class="PropText">GoSub SquareRoot</p>
  78.   <p class="PropText">Print "The square root of";iInputb;" is";iInputc</p>
  79.   <p class="PropText">Exit Sub</p>
  80.   <p class="PropText">SquareRoot:</p>
  81.   <p class="PropText">iInputc=sqr(iInputc)</p>
  82.   <p class="PropText">Return</p>
  83.   <p class="PropText">End Sub</p>
  84.  </body></html>